<?php
/* tblProduct */
class Product extends Form
	{
		protected $_ID                 = array();
		protected $_Product                 = array();
		protected $_Description                 = array();
		protected $_ExtraDescription                 = array();
		protected $_Weight                 = array();
		protected $_OwnProductCode                 = array();
		protected $_Barcode                 = array();
		protected $_Supplier                 = array();
		protected $_SupplierProductID                 = array();
		protected $_Category                 = array();
		protected $_QuantityPerUnit                 = array();
		protected $_CostPrice                 = array();
		protected $_UnitPrice                 = array();
		protected $_FullPrice                 = array();
		protected $_VatRate                 = array();
		protected $_UnitsInStock                 = array();
		protected $_UnitsOnOrder                 = array();
		protected $_ReorderLevel                 = array();
		protected $_Discontinued                 = array();
		protected $_UploadedPicture                 = array();
		protected $_PromotionalItem                 = array();
		protected $_MetaTitle                 = array();
		protected $_MetaDescription                 = array();
		protected $_MetaKeyword                 = array();
		protected $_MetaComment                 = array();
		protected $_DisplayOrder                 = array();
		protected $_DateAdded                 = array();
		protected $_DateUpdated                 = array();
		protected $_UpdatedBy                 = array();

		function __construct($iID = null)
		{
			parent::__construct();
			if(($iID) && ($this->set_IDValue($iID)))
				$this->_getRow();
		}
		
		/* Retrieve updateable row from MySql and populate properties */
		private function _getRow()
		{
	
			$strSql = 	"SELECT * 
						 FROM tblProduct
						 WHERE ID = '".$this->get_ID()."'";
			//echo nl2br($strSql);
			/* '$this' is passed by reference to parent->getDataObjectRow as parents can't inherit from child */
			return($this->getDataObjectRow($strSql, $this));
		}
		
		public function get_ID()
		{
				return  $this->_get_IDValue();
		}

		private function _get_IDValue()
		{
			if(isset($this->_ID['value']))
				return $this->_ID['value'];
			else
				return false;
		}

		public function get_Product()
		{
				return  $this->_get_ProductValue();
		}

		private function _get_ProductValue()
		{
			if(isset($this->_Product['value']))
				return $this->_Product['value'];
			else
				return false;
		}

		public function get_Description()
		{
				return  $this->_get_DescriptionValue();
		}

		private function _get_DescriptionValue()
		{
			if(isset($this->_Description['value']))
				return $this->_Description['value'];
			else
				return false;
		}

		public function get_ExtraDescription()
		{
				return  $this->_get_ExtraDescriptionValue();
		}

		private function _get_ExtraDescriptionValue()
		{
			if(isset($this->_ExtraDescription['value']))
				return $this->_ExtraDescription['value'];
			else
				return false;
		}

		public function get_Weight()
		{
				return  $this->_get_WeightValue();
		}

		private function _get_WeightValue()
		{
			if(isset($this->_Weight['value']))
				return $this->_Weight['value'];
			else
				return false;
		}

		public function get_OwnProductCode()
		{
				return  $this->_get_OwnProductCodeValue();
		}

		private function _get_OwnProductCodeValue()
		{
			if(isset($this->_OwnProductCode['value']))
				return $this->_OwnProductCode['value'];
			else
				return false;
		}

		public function get_Barcode()
		{
				return  $this->_get_BarcodeValue();
		}

		private function _get_BarcodeValue()
		{
			if(isset($this->_Barcode['value']))
				return $this->_Barcode['value'];
			else
				return false;
		}

		public function get_Supplier()
		{
				return  $this->_get_SupplierValue();
		}

		private function _get_SupplierValue()
		{
			if(isset($this->_Supplier['value']))
				return $this->_Supplier['value'];
			else
				return false;
		}

		public function get_SupplierProductID()
		{
				return  $this->_get_SupplierProductIDValue();
		}

		private function _get_SupplierProductIDValue()
		{
			if(isset($this->_SupplierProductID['value']))
				return $this->_SupplierProductID['value'];
			else
				return false;
		}

		public function get_Category()
		{
				return  $this->_get_CategoryValue();
		}

		private function _get_CategoryValue()
		{
			if(isset($this->_Category['value']))
				return $this->_Category['value'];
			else
				return false;
		}

		public function get_QuantityPerUnit()
		{
				return  $this->_get_QuantityPerUnitValue();
		}

		private function _get_QuantityPerUnitValue()
		{
			if(isset($this->_QuantityPerUnit['value']))
				return $this->_QuantityPerUnit['value'];
			else
				return false;
		}

		public function get_CostPrice()
		{
				return  $this->_get_CostPriceValue();
		}

		private function _get_CostPriceValue()
		{
			if(isset($this->_CostPrice['value']))
				return $this->_CostPrice['value'];
			else
				return false;
		}

		public function get_UnitPrice()
		{
				return  $this->_get_UnitPriceValue();
		}

		private function _get_UnitPriceValue()
		{
			if(isset($this->_UnitPrice['value']))
				return $this->_UnitPrice['value'];
			else
				return false;
		}

		public function get_FullPrice()
		{
				return  $this->_get_FullPriceValue();
		}

		private function _get_FullPriceValue()
		{
			if(isset($this->_FullPrice['value']))
				return $this->_FullPrice['value'];
			else
				return false;
		}

		public function get_VatRate()
		{
				return  $this->_get_VatRateValue();
		}

		private function _get_VatRateValue()
		{
			if(isset($this->_VatRate['value']))
				return $this->_VatRate['value'];
			else
				return false;
		}

		public function get_UnitsInStock()
		{
				return  $this->_get_UnitsInStockValue();
		}

		private function _get_UnitsInStockValue()
		{
			if(isset($this->_UnitsInStock['value']))
				return $this->_UnitsInStock['value'];
			else
				return false;
		}

		public function get_UnitsOnOrder()
		{
				return  $this->_get_UnitsOnOrderValue();
		}

		private function _get_UnitsOnOrderValue()
		{
			if(isset($this->_UnitsOnOrder['value']))
				return $this->_UnitsOnOrder['value'];
			else
				return false;
		}

		public function get_ReorderLevel()
		{
				return  $this->_get_ReorderLevelValue();
		}

		private function _get_ReorderLevelValue()
		{
			if(isset($this->_ReorderLevel['value']))
				return $this->_ReorderLevel['value'];
			else
				return false;
		}

		public function get_Discontinued()
		{
				return  $this->_get_DiscontinuedValue();
		}

		private function _get_DiscontinuedValue()
		{
			if(isset($this->_Discontinued['value']))
				return $this->_Discontinued['value'];
			else
				return false;
		}

		public function get_UploadedPicture()
		{
				return  $this->_get_UploadedPictureValue();
		}

		private function _get_UploadedPictureValue()
		{
			if(isset($this->_UploadedPicture['value']))
				return $this->_UploadedPicture['value'];
			else
				return false;
		}

		public function get_PromotionalItem()
		{
				return  $this->_get_PromotionalItemValue();
		}

		private function _get_PromotionalItemValue()
		{
			if(isset($this->_PromotionalItem['value']))
				return $this->_PromotionalItem['value'];
			else
				return false;
		}

		public function get_MetaTitle()
		{
				return  $this->_get_MetaTitleValue();
		}

		private function _get_MetaTitleValue()
		{
			if(isset($this->_MetaTitle['value']))
				return $this->_MetaTitle['value'];
			else
				return false;
		}

		public function get_MetaDescription()
		{
				return  $this->_get_MetaDescriptionValue();
		}

		private function _get_MetaDescriptionValue()
		{
			if(isset($this->_MetaDescription['value']))
				return $this->_MetaDescription['value'];
			else
				return false;
		}

		public function get_MetaKeyword()
		{
				return  $this->_get_MetaKeywordValue();
		}

		private function _get_MetaKeywordValue()
		{
			if(isset($this->_MetaKeyword['value']))
				return $this->_MetaKeyword['value'];
			else
				return false;
		}

		public function get_MetaComment()
		{
				return  $this->_get_MetaCommentValue();
		}

		private function _get_MetaCommentValue()
		{
			if(isset($this->_MetaComment['value']))
				return $this->_MetaComment['value'];
			else
				return false;
		}

		public function get_DisplayOrder()
		{
				return  $this->_get_DisplayOrderValue();
		}

		private function _get_DisplayOrderValue()
		{
			if(isset($this->_DisplayOrder['value']))
				return $this->_DisplayOrder['value'];
			else
				return false;
		}

		public function get_DateAdded()
		{
				return  $this->_get_DateAddedValue();
		}

		private function _get_DateAddedValue()
		{
			if(isset($this->_DateAdded['value']))
				return $this->_DateAdded['value'];
			else
				return false;
		}

		public function get_DateUpdated()
		{
				return  $this->_get_DateUpdatedValue();
		}

		private function _get_DateUpdatedValue()
		{
			if(isset($this->_DateUpdated['value']))
				return $this->_DateUpdated['value'];
			else
				return false;
		}

		public function get_UpdatedBy()
		{
				return  $this->_get_UpdatedByValue();
		}

		private function _get_UpdatedByValue()
		{
			if(isset($this->_UpdatedBy['value']))
				return $this->_UpdatedBy['value'];
			else
				return false;
		}


		public function set_IDValue($strID)
		{
			if($this->validateInput("validateNumber", $strID, "ID "))
					return($this->_setNewValue($this->_ID, $strID));
			else
					return false;
		}

		public function set_ProductValue($strProduct)
		{
			if($this->validateInput("validatexxxxx", $strProduct, "Product "))
					return($this->_setNewValue($this->_Product, $strProduct));
			else
					return false;
		}

		public function set_DescriptionValue($strDescription)
		{
			if($this->validateInput("validatexxxxx", $strDescription, "Description "))
					return($this->_setNewValue($this->_Description, $strDescription));
			else
					return false;
		}

		public function set_ExtraDescriptionValue($strExtraDescription)
		{
			if($this->validateInput("validatexxxxx", $strExtraDescription, "ExtraDescription "))
					return($this->_setNewValue($this->_ExtraDescription, $strExtraDescription));
			else
					return false;
		}

		public function set_WeightValue($strWeight)
		{
			if($this->validateInput("validatexxxxx", $strWeight, "Weight "))
					return($this->_setNewValue($this->_Weight, $strWeight));
			else
					return false;
		}

		public function set_OwnProductCodeValue($strOwnProductCode)
		{
			if($this->validateInput("validatexxxxx", $strOwnProductCode, "OwnProductCode "))
					return($this->_setNewValue($this->_OwnProductCode, $strOwnProductCode));
			else
					return false;
		}

		public function set_BarcodeValue($strBarcode)
		{
			if($this->validateInput("validatexxxxx", $strBarcode, "Barcode "))
					return($this->_setNewValue($this->_Barcode, $strBarcode));
			else
					return false;
		}

		public function set_SupplierValue($strSupplier)
		{
			if($this->validateInput("validatexxxxx", $strSupplier, "Supplier "))
					return($this->_setNewValue($this->_Supplier, $strSupplier));
			else
					return false;
		}

		public function set_SupplierProductIDValue($strSupplierProductID)
		{
			if($this->validateInput("validatexxxxx", $strSupplierProductID, "SupplierProductID "))
					return($this->_setNewValue($this->_SupplierProductID, $strSupplierProductID));
			else
					return false;
		}

		public function set_CategoryValue($strCategory)
		{
			if($this->validateInput("validateNumber", $strCategory, "Category "))
					return($this->_setNewValue($this->_Category, $strCategory));
			else
					return false;
		}

		public function set_QuantityPerUnitValue($strQuantityPerUnit)
		{
			if($this->validateInput("validatexxxxx", $strQuantityPerUnit, "QuantityPerUnit "))
					return($this->_setNewValue($this->_QuantityPerUnit, $strQuantityPerUnit));
			else
					return false;
		}

		public function set_CostPriceValue($strCostPrice)
		{
			if($this->validateInput("validatexxxxx", $strCostPrice, "CostPrice "))
					return($this->_setNewValue($this->_CostPrice, $strCostPrice));
			else
					return false;
		}

		public function set_UnitPriceValue($strUnitPrice)
		{
			if($this->validateInput("validatexxxxx", $strUnitPrice, "UnitPrice "))
					return($this->_setNewValue($this->_UnitPrice, $strUnitPrice));
			else
					return false;
		}

		public function set_FullPriceValue($strFullPrice)
		{
			if($this->validateInput("validatexxxxx", $strFullPrice, "FullPrice "))
					return($this->_setNewValue($this->_FullPrice, $strFullPrice));
			else
					return false;
		}

		public function set_VatRateValue($strVatRate)
		{
			if($this->validateInput("validatexxxxx", $strVatRate, "VatRate "))
					return($this->_setNewValue($this->_VatRate, $strVatRate));
			else
					return false;
		}

		public function set_UnitsInStockValue($strUnitsInStock)
		{
			if($this->validateInput("validateNumber", $strUnitsInStock, "UnitsInStock "))
					return($this->_setNewValue($this->_UnitsInStock, $strUnitsInStock));
			else
					return false;
		}

		public function set_UnitsOnOrderValue($strUnitsOnOrder)
		{
			if($this->validateInput("validatexxxxx", $strUnitsOnOrder, "UnitsOnOrder "))
					return($this->_setNewValue($this->_UnitsOnOrder, $strUnitsOnOrder));
			else
					return false;
		}

		public function set_ReorderLevelValue($strReorderLevel)
		{
			if($this->validateInput("validatexxxxx", $strReorderLevel, "ReorderLevel "))
					return($this->_setNewValue($this->_ReorderLevel, $strReorderLevel));
			else
					return false;
		}

		public function set_DiscontinuedValue($strDiscontinued)
		{
			$strError = "";
			if(validateRange($strDiscontinued, 0, 1, $strError))
				return($this->_setNewValue($this->_Discontinued, $strDiscontinued));
			else{
				$this->_setFailScreens($strError, true);
				return false;
			}
		}

		public function set_UploadedPictureValue($strUploadedPicture)
		{
			if($this->validateInput("validatexxxxx", $strUploadedPicture, "UploadedPicture "))
					return($this->_setNewValue($this->_UploadedPicture, $strUploadedPicture));
			else
					return false;
		}

		public function set_PromotionalItemValue($strPromotionalItem)
		{
			if($this->validateInput("validatexxxxx", $strPromotionalItem, "PromotionalItem "))
					return($this->_setNewValue($this->_PromotionalItem, $strPromotionalItem));
			else
					return false;
		}

		public function set_MetaTitleValue($strMetaTitle)
		{
			if($this->validateInput("validatexxxxx", $strMetaTitle, "MetaTitle "))
					return($this->_setNewValue($this->_MetaTitle, $strMetaTitle));
			else
					return false;
		}

		public function set_MetaDescriptionValue($strMetaDescription)
		{
			if($this->validateInput("validatexxxxx", $strMetaDescription, "MetaDescription "))
					return($this->_setNewValue($this->_MetaDescription, $strMetaDescription));
			else
					return false;
		}

		public function set_MetaKeywordValue($strMetaKeyword)
		{
			if($this->validateInput("validatexxxxx", $strMetaKeyword, "MetaKeyword "))
					return($this->_setNewValue($this->_MetaKeyword, $strMetaKeyword));
			else
					return false;
		}

		public function set_MetaCommentValue($strMetaComment)
		{
			if($this->validateInput("validatexxxxx", $strMetaComment, "MetaComment "))
					return($this->_setNewValue($this->_MetaComment, $strMetaComment));
			else
					return false;
		}

		public function set_DisplayOrderValue($strDisplayOrder)
		{
			if($this->validateInput("validatexxxxx", $strDisplayOrder, "DisplayOrder "))
					return($this->_setNewValue($this->_DisplayOrder, $strDisplayOrder));
			else
					return false;
		}

		public function set_DateAddedValue($strDateAdded)
		{
			if($this->validateInput("validatexxxxx", $strDateAdded, "DateAdded "))
					return($this->_setNewValue($this->_DateAdded, $strDateAdded));
			else
					return false;
		}

		public function set_DateUpdatedValue($strDateUpdated)
		{
			if($this->validateInput("validatexxxxx", $strDateUpdated, "DateUpdated "))
					return($this->_setNewValue($this->_DateUpdated, $strDateUpdated));
			else
					return false;
		}

		public function set_UpdatedByValue($strUpdatedBy)
		{
			if($this->validateInput("validatexxxxx", $strUpdatedBy, "UpdatedBy "))
					return($this->_setNewValue($this->_UpdatedBy, $strUpdatedBy));
			else
					return false;
		}
		public function updateProduct()
		{
			if($this->_boFailedValidation)
					return false;
					$strErrorMsg = "";
					$strSuccessMsg = "";
			if($this->get_ID() == "")
					return $this->_setFailScreens("Update aborted no record selected.", true);

			$strJoin = "";
			$strSql = "UPDATE tblProduct
					SET ";
					if($this->_ID['updated'])
					{
						$strSql .= $strJoin." ID = '".$this->_ID['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "ID changed from '".$this->_ID['oldvalue']."' to '".$this->_ID['value']."'<br/>";
						$strErrorMsg .= "ID not updated<br/>";
					}

					if($this->_Product['updated'])
					{
						$strSql .= $strJoin." Product = '".$this->_Product['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Product changed from '".$this->_Product['oldvalue']."' to '".$this->_Product['value']."'<br/>";
						$strErrorMsg .= "Product not updated<br/>";
					}

					if($this->_Description['updated'])
					{
						$strSql .= $strJoin." Description = '".$this->_Description['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Description changed from '".$this->_Description['oldvalue']."' to '".$this->_Description['value']."'<br/>";
						$strErrorMsg .= "Description not updated<br/>";
					}

					if($this->_ExtraDescription['updated'])
					{
						$strSql .= $strJoin." ExtraDescription = '".$this->_ExtraDescription['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "ExtraDescription changed from '".$this->_ExtraDescription['oldvalue']."' to '".$this->_ExtraDescription['value']."'<br/>";
						$strErrorMsg .= "ExtraDescription not updated<br/>";
					}

					if($this->_Weight['updated'])
					{
						$strSql .= $strJoin." Weight = '".$this->_Weight['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Weight changed from '".$this->_Weight['oldvalue']."' to '".$this->_Weight['value']."'<br/>";
						$strErrorMsg .= "Weight not updated<br/>";
					}

					if($this->_OwnProductCode['updated'])
					{
						$strSql .= $strJoin." OwnProductCode = '".$this->_OwnProductCode['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "OwnProductCode changed from '".$this->_OwnProductCode['oldvalue']."' to '".$this->_OwnProductCode['value']."'<br/>";
						$strErrorMsg .= "OwnProductCode not updated<br/>";
					}

					if($this->_Barcode['updated'])
					{
						$strSql .= $strJoin." Barcode = '".$this->_Barcode['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Barcode changed from '".$this->_Barcode['oldvalue']."' to '".$this->_Barcode['value']."'<br/>";
						$strErrorMsg .= "Barcode not updated<br/>";
					}

					if($this->_Supplier['updated'])
					{
						$strSql .= $strJoin." Supplier = '".$this->_Supplier['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Supplier changed from '".$this->_Supplier['oldvalue']."' to '".$this->_Supplier['value']."'<br/>";
						$strErrorMsg .= "Supplier not updated<br/>";
					}

					if($this->_SupplierProductID['updated'])
					{
						$strSql .= $strJoin." SupplierProductID = '".$this->_SupplierProductID['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "SupplierProductID changed from '".$this->_SupplierProductID['oldvalue']."' to '".$this->_SupplierProductID['value']."'<br/>";
						$strErrorMsg .= "SupplierProductID not updated<br/>";
					}

					if($this->_Category['updated'])
					{
						$strSql .= $strJoin." Category = '".$this->_Category['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Category changed from '".$this->_Category['oldvalue']."' to '".$this->_Category['value']."'<br/>";
						$strErrorMsg .= "Category not updated<br/>";
					}

					if($this->_QuantityPerUnit['updated'])
					{
						$strSql .= $strJoin." QuantityPerUnit = '".$this->_QuantityPerUnit['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "QuantityPerUnit changed from '".$this->_QuantityPerUnit['oldvalue']."' to '".$this->_QuantityPerUnit['value']."'<br/>";
						$strErrorMsg .= "QuantityPerUnit not updated<br/>";
					}

					if($this->_CostPrice['updated'])
					{
						$strSql .= $strJoin." CostPrice = '".$this->_CostPrice['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "CostPrice changed from '".$this->_CostPrice['oldvalue']."' to '".$this->_CostPrice['value']."'<br/>";
						$strErrorMsg .= "CostPrice not updated<br/>";
					}

					if($this->_UnitPrice['updated'])
					{
						$strSql .= $strJoin." UnitPrice = '".$this->_UnitPrice['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "UnitPrice changed from '".$this->_UnitPrice['oldvalue']."' to '".$this->_UnitPrice['value']."'<br/>";
						$strErrorMsg .= "UnitPrice not updated<br/>";
					}

					if($this->_FullPrice['updated'])
					{
						$strSql .= $strJoin." FullPrice = '".$this->_FullPrice['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "FullPrice changed from '".$this->_FullPrice['oldvalue']."' to '".$this->_FullPrice['value']."'<br/>";
						$strErrorMsg .= "FullPrice not updated<br/>";
					}

					if($this->_VatRate['updated'])
					{
						$strSql .= $strJoin." VatRate = '".$this->_VatRate['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "VatRate changed from '".$this->_VatRate['oldvalue']."' to '".$this->_VatRate['value']."'<br/>";
						$strErrorMsg .= "VatRate not updated<br/>";
					}

					if($this->_UnitsInStock['updated'])
					{
						$strSql .= $strJoin." UnitsInStock = '".$this->_UnitsInStock['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "UnitsInStock changed from '".$this->_UnitsInStock['oldvalue']."' to '".$this->_UnitsInStock['value']."'<br/>";
						$strErrorMsg .= "UnitsInStock not updated<br/>";
					}

					if($this->_UnitsOnOrder['updated'])
					{
						$strSql .= $strJoin." UnitsOnOrder = '".$this->_UnitsOnOrder['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "UnitsOnOrder changed from '".$this->_UnitsOnOrder['oldvalue']."' to '".$this->_UnitsOnOrder['value']."'<br/>";
						$strErrorMsg .= "UnitsOnOrder not updated<br/>";
					}

					if($this->_ReorderLevel['updated'])
					{
						$strSql .= $strJoin." ReorderLevel = '".$this->_ReorderLevel['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "ReorderLevel changed from '".$this->_ReorderLevel['oldvalue']."' to '".$this->_ReorderLevel['value']."'<br/>";
						$strErrorMsg .= "ReorderLevel not updated<br/>";
					}

					if($this->_Discontinued['updated'])
					{
						$strSql .= $strJoin." Discontinued = '".$this->_Discontinued['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Discontinued changed from '".$this->_Discontinued['oldvalue']."' to '".$this->_Discontinued['value']."'<br/>";
						$strErrorMsg .= "Discontinued not updated<br/>";
					}

					if($this->_UploadedPicture['updated'])
					{
						$strSql .= $strJoin." UploadedPicture = '".$this->_UploadedPicture['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "UploadedPicture changed from '".$this->_UploadedPicture['oldvalue']."' to '".$this->_UploadedPicture['value']."'<br/>";
						$strErrorMsg .= "UploadedPicture not updated<br/>";
					}

					if($this->_PromotionalItem['updated'])
					{
						$strSql .= $strJoin." PromotionalItem = '".$this->_PromotionalItem['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "PromotionalItem changed from '".$this->_PromotionalItem['oldvalue']."' to '".$this->_PromotionalItem['value']."'<br/>";
						$strErrorMsg .= "PromotionalItem not updated<br/>";
					}

					if($this->_MetaTitle['updated'])
					{
						$strSql .= $strJoin." MetaTitle = '".$this->_MetaTitle['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "MetaTitle changed from '".$this->_MetaTitle['oldvalue']."' to '".$this->_MetaTitle['value']."'<br/>";
						$strErrorMsg .= "MetaTitle not updated<br/>";
					}

					if($this->_MetaDescription['updated'])
					{
						$strSql .= $strJoin." MetaDescription = '".$this->_MetaDescription['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "MetaDescription changed from '".$this->_MetaDescription['oldvalue']."' to '".$this->_MetaDescription['value']."'<br/>";
						$strErrorMsg .= "MetaDescription not updated<br/>";
					}

					if($this->_MetaKeyword['updated'])
					{
						$strSql .= $strJoin." MetaKeyword = '".$this->_MetaKeyword['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "MetaKeyword changed from '".$this->_MetaKeyword['oldvalue']."' to '".$this->_MetaKeyword['value']."'<br/>";
						$strErrorMsg .= "MetaKeyword not updated<br/>";
					}

					if($this->_MetaComment['updated'])
					{
						$strSql .= $strJoin." MetaComment = '".$this->_MetaComment['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "MetaComment changed from '".$this->_MetaComment['oldvalue']."' to '".$this->_MetaComment['value']."'<br/>";
						$strErrorMsg .= "MetaComment not updated<br/>";
					}

					if($this->_DisplayOrder['updated'])
					{
						$strSql .= $strJoin." DisplayOrder = '".$this->_DisplayOrder['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "DisplayOrder changed from '".$this->_DisplayOrder['oldvalue']."' to '".$this->_DisplayOrder['value']."'<br/>";
						$strErrorMsg .= "DisplayOrder not updated<br/>";
					}

					if($this->_DateAdded['updated'])
					{
						$strSql .= $strJoin." DateAdded = '".$this->_DateAdded['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "DateAdded changed from '".$this->_DateAdded['oldvalue']."' to '".$this->_DateAdded['value']."'<br/>";
						$strErrorMsg .= "DateAdded not updated<br/>";
					}

					if($this->_DateUpdated['updated'])
					{
						$strSql .= $strJoin." DateUpdated = '".$this->_DateUpdated['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "DateUpdated changed from '".$this->_DateUpdated['oldvalue']."' to '".$this->_DateUpdated['value']."'<br/>";
						$strErrorMsg .= "DateUpdated not updated<br/>";
					}

					if($this->_UpdatedBy['updated'])
					{
						$strSql .= $strJoin." UpdatedBy = '".$this->_UpdatedBy['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "UpdatedBy changed from '".$this->_UpdatedBy['oldvalue']."' to '".$this->_UpdatedBy['value']."'<br/>";
						$strErrorMsg .= "UpdatedBy not updated<br/>";
					}

			$strSql .= "WHERE ID = ". $this->get_ID();
			//Only execute sql if there is something to update.
			if($strJoin == ",")
			{
				//echo nl2br($strSql);
				if(!($DatabaseResult = mysql_query($strSql)))
					return $this->_setFailScreens($strErrorMsg);
				$GLOBALS['arrSuccessMessages'][] = $strSuccessMsg;
			}else
				$GLOBALS['arrSuccessMessages'][] = "No data has changed, so no updates made.";
			return(TRUE);
		}
		
		public function delete_tblProduct()
		{
			if($this->get_IDValue() == "")
				return $this->_setFailScreens("Delete aborted no record selected.", true);
			
	
			/* Deleted port forward from agg */
			$strSql =   "DELETE FROM tblProduct
	   					  WHERE ID		= ".$this->get_IDValue();
	
			$qryDeletetblProduct = new MySqlResults($strSql);
	
			if(!$qryDeletetblProduct->result)
				return ($this->_setFailScreens("An error occurred while trying to delete database entry."));
	
	
			$GLOBALS['arrSuccessMessages'][] = " has been removed";
			return true;
		}
		
		public function insertProduct()
		{
			/* Check that all required fields have been set */
			if (!($this->_validateAllFieldsSet()))
			{
				return ($this->_setFailScreens("Fields required to add a new record haven't all been set", true));
			}
			
			$strSql =   "INSERT INTO tblProduct
						  (		 	Product
		, 	Description
		, 	ExtraDescription
		, 	Weight
		, 	OwnProductCode
		, 	Barcode
		, 	Supplier
		, 	SupplierProductID
		, 	Category
		, 	QuantityPerUnit
		, 	CostPrice
		, 	UnitPrice
		, 	FullPrice
		, 	VatRate
		, 	UnitsInStock
		, 	UnitsOnOrder
		, 	ReorderLevel
		, 	Discontinued
		, 	UploadedPicture
		, 	PromotionalItem
		, 	MetaTitle
		, 	MetaDescription
		, 	MetaKeyword
		, 	MetaComment
		, 	DisplayOrder
		, 	DateAdded
		, 	DateUpdated
		, 	UpdatedBy
)VALUE(
		 	'".$this->get_Product()."' 
		, 	'".$this->get_Description()."' 
		, 	'".$this->get_ExtraDescription()."' 
		, 	'".$this->get_Weight()."' 
		, 	'".$this->get_OwnProductCode()."' 
		, 	'".$this->get_Barcode()."' 
		, 	'".$this->get_Supplier()."' 
		, 	'".$this->get_SupplierProductID()."' 
		, 	'".$this->get_Category()."' 
		, 	'".$this->get_QuantityPerUnit()."' 
		, 	'".$this->get_CostPrice()."' 
		, 	'".$this->get_UnitPrice()."' 
		, 	'".$this->get_FullPrice()."' 
		, 	'".$this->get_VatRate()."' 
		, 	'".$this->get_UnitsInStock()."' 
		, 	'".$this->get_UnitsOnOrder()."' 
		, 	'".$this->get_ReorderLevel()."' 
		, 	'".$this->get_Discontinued()."' 
		, 	'".$this->get_UploadedPicture()."' 
		, 	'".$this->get_PromotionalItem()."' 
		, 	'".$this->get_MetaTitle()."' 
		, 	'".$this->get_MetaDescription()."' 
		, 	'".$this->get_MetaKeyword()."' 
		, 	'".$this->get_MetaComment()."' 
		, 	'".$this->get_DisplayOrder()."' 
		, 	'".$this->get_DateAdded()."' 
		, 	'".$this->get_DateUpdated()."' 
		, 	'".$this->get_UpdatedBy()."' 
			)";
			
			$qryInserttblProduct = new MySqlResults($strSql);
		if ($qryInserttblProduct->result)
		{
			/*Extra post sql processing  */
		}else
			return $this->_setFailScreens("Unable to add to  tblProduct");
			
		return true;
	}
	/**
	 * public function to search tblProduct
	 * @param any that are set in $this
	 * @return MySqlResults
	 */
	public function searchProduct($iLimit = null, $boRandom = false)
	{
		$strJoin = " WHERE ";
		$strSql = "SELECT * 
                   FROM tblProduct ";

		if($this->_get_IDValue())
		{
			$strSql .= $strJoin." ID = '".$this->_get_IDValue()."' ";
			$strJoin = " AND ";
		}

		if($this->_get_ProductValue())
		{
			$strSql .= $strJoin." Product = '".$this->_get_ProductValue()."' ";
			$strJoin = " AND ";
		}

		if($this->_get_DescriptionValue())
		{
			$strSql .= $strJoin." Description = '".$this->_get_DescriptionValue()."' ";
			$strJoin = " AND ";
		}

		if($this->_get_ExtraDescriptionValue())
		{
			$strSql .= $strJoin." ExtraDescription = '".$this->_get_ExtraDescriptionValue()."' ";
			$strJoin = " AND ";
		}

		if($this->_get_WeightValue())
		{
			$strSql .= $strJoin." Weight = '".$this->_get_WeightValue()."' ";
			$strJoin = " AND ";
		}

		if($this->_get_OwnProductCodeValue())
		{
			$strSql .= $strJoin." OwnProductCode = '".$this->_get_OwnProductCodeValue()."' ";
			$strJoin = " AND ";
		}

		if($this->_get_BarcodeValue())
		{
			$strSql .= $strJoin." Barcode = '".$this->_get_BarcodeValue()."' ";
			$strJoin = " AND ";
		}

		if($this->_get_SupplierValue())
		{
			$strSql .= $strJoin." Supplier = '".$this->_get_SupplierValue()."' ";
			$strJoin = " AND ";
		}

		if($this->_get_SupplierProductIDValue())
		{
			$strSql .= $strJoin." SupplierProductID = '".$this->_get_SupplierProductIDValue()."' ";
			$strJoin = " AND ";
		}

		if($this->_get_CategoryValue())
		{
			$strSql .= $strJoin." Category = '".$this->_get_CategoryValue()."' ";
			$strJoin = " AND ";
		}

		if($this->_get_QuantityPerUnitValue())
		{
			$strSql .= $strJoin." QuantityPerUnit = '".$this->_get_QuantityPerUnitValue()."' ";
			$strJoin = " AND ";
		}

		if($this->_get_CostPriceValue())
		{
			$strSql .= $strJoin." CostPrice = '".$this->_get_CostPriceValue()."' ";
			$strJoin = " AND ";
		}

		if($this->_get_UnitPriceValue())
		{
			$strSql .= $strJoin." UnitPrice = '".$this->_get_UnitPriceValue()."' ";
			$strJoin = " AND ";
		}

		if($this->_get_FullPriceValue())
		{
			$strSql .= $strJoin." FullPrice = '".$this->_get_FullPriceValue()."' ";
			$strJoin = " AND ";
		}

		if($this->_get_VatRateValue())
		{
			$strSql .= $strJoin." VatRate = '".$this->_get_VatRateValue()."' ";
			$strJoin = " AND ";
		}

		if($this->_get_UnitsInStockValue())
		{
			$strSql .= $strJoin." UnitsInStock >= '".$this->_get_UnitsInStockValue()."' ";
			$strJoin = " AND ";
		}

		if($this->_get_UnitsOnOrderValue())
		{
			$strSql .= $strJoin." UnitsOnOrder = '".$this->_get_UnitsOnOrderValue()."' ";
			$strJoin = " AND ";
		}

		if($this->_get_ReorderLevelValue())
		{
			$strSql .= $strJoin." ReorderLevel = '".$this->_get_ReorderLevelValue()."' ";
			$strJoin = " AND ";
		}

		if($this->_get_DiscontinuedValue() !== false)
		{
			$strSql .= $strJoin." Discontinued = '".$this->_get_DiscontinuedValue()."' ";
			$strJoin = " AND ";
		}

		if($this->_get_UploadedPictureValue())
		{
			$strSql .= $strJoin." UploadedPicture = '".$this->_get_UploadedPictureValue()."' ";
			$strJoin = " AND ";
		}

		if($this->_get_PromotionalItemValue())
		{
			$strSql .= $strJoin." PromotionalItem = '".$this->_get_PromotionalItemValue()."' ";
			$strJoin = " AND ";
		}

		if($this->_get_MetaTitleValue())
		{
			$strSql .= $strJoin." MetaTitle = '".$this->_get_MetaTitleValue()."' ";
			$strJoin = " AND ";
		}

		if($this->_get_MetaDescriptionValue())
		{
			$strSql .= $strJoin." MetaDescription = '".$this->_get_MetaDescriptionValue()."' ";
			$strJoin = " AND ";
		}

		if($this->_get_MetaKeywordValue())
		{
			$strSql .= $strJoin." MetaKeyword = '".$this->_get_MetaKeywordValue()."' ";
			$strJoin = " AND ";
		}

		if($this->_get_MetaCommentValue())
		{
			$strSql .= $strJoin." MetaComment = '".$this->_get_MetaCommentValue()."' ";
			$strJoin = " AND ";
		}

		if($this->_get_DisplayOrderValue())
		{
			$strSql .= $strJoin." DisplayOrder = '".$this->_get_DisplayOrderValue()."' ";
			$strJoin = " AND ";
		}

		if($this->_get_DateAddedValue())
		{
			$strSql .= $strJoin." DateAdded = '".$this->_get_DateAddedValue()."' ";
			$strJoin = " AND ";
		}

		if($this->_get_DateUpdatedValue())
		{
			$strSql .= $strJoin." DateUpdated = '".$this->_get_DateUpdatedValue()."' ";
			$strJoin = " AND ";
		}

		if($this->_get_UpdatedByValue())
		{
			$strSql .= $strJoin." UpdatedBy = '".$this->_get_UpdatedByValue()."' ";
			$strJoin = " AND ";
		}

		if(($iLimit) && (is_numeric($iLimit)))
		{
			$strLimit = " LIMIT ".$iLimit;
			if($boRandom)
				$strSql .= " ORDER BY RAND() ".$strLimit;
		}
		//echo nl2br($strSql);
		
		$qrySearchtblProduct = new MySqlResults($strSql);
		return $qrySearchtblProduct;	
    }
    
    /**
     * Get Products Name based on index ID
     * @param integer $ID
     */
    public static function getName($ID)
    {
    	$objProduct = new Product($ID);
    	if($objProduct->numrows == 1)
    		return $objProduct->get_Product();
    	else 
    		return false;
    }
}

?>